<template>
  <div class="common-layout">
    <el-container style="height: 100%">
      <el-aside style="margin-right:20px" width="200px">
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          :collapse="isCollapse"
          @open="handleOpen"
          @close="handleClose"
          @select="handleSelect"
          style="height: 100%"
        >
          <el-menu-item index="home">
            <el-icon><setting /></el-icon>
            <template #title>首页</template>
          </el-menu-item>
          <el-menu-item index="user">
            <el-icon><setting /></el-icon>
            <template #title>个人中心</template>
          </el-menu-item>
          <el-menu-item index="app-vue3">
            <el-icon><setting /></el-icon>
            <template #title>app-vue3</template>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>金智维</el-header>
        <el-main>
          <router-view id='router-container' />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter } from "vue-router";
import { ref } from "vue";
import { Setting } from "@element-plus/icons-vue";
//初始化路由
const router = useRouter();

const isCollapse = ref(false);
const handleOpen = (key, keyPath) => {
  console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  console.log(key, keyPath);
};
let handleSelect = (key) => {
  if (key == 'home') {
    router.push({ path: '/' })
  } else if (key == 'user') {
    router.push({ name: 'app-vue2' })
  } else {
    router.push({ path: '/app-vite' })
  }
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
body,
html {
  width: 100%;
  height: 100%;
}
#app {
  width: 100%;
  height: 100%;
  background-color: #f5f5f5;
}
.el-header {
  background-color: #fff;
  display: flex;
  align-items: center;
}
.el-main {
  margin-top: 10px;
  background-color: #fff;
  height: calc(100% - 70px);
}
.common-layout {
  width: 100%;
  height: 100%;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>
